﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils.Drawing
{
    public class LayerDepth
    {
        public const int DIGITS_PER_LEVEL = 2;

        float depth = 0.5f;
        int hierarchyLevel = 0;
        LayerDepth parent;

        public float Depth 
        { 
            get 
            {
                if (parent != null)
                {
                    return depth * (float)Math.Pow(0.1f, (double)(hierarchyLevel * DIGITS_PER_LEVEL)) + parent.Depth;
                }
                else
                {
                    return depth;
                }
            } 
        }

        public int HierarchyLevel { get { return hierarchyLevel; } }


        public LayerDepth(float depth)
        {
            this.depth = depth;
        }

        public LayerDepth(float depth, LayerDepth parent)
        {
            this.depth = depth;
            if(parent != null)
            {
                this.parent = parent;
                hierarchyLevel = parent.HierarchyLevel + 1;
            }
        }

        public static implicit operator float(LayerDepth layerDepth)
        {
            return layerDepth.Depth;
        }

        public static implicit operator LayerDepth(float f)
        {
            return new LayerDepth(f);
        }
    }
}
